package com.xjc.business.controller.dooradmin;

import com.xjc.business.entity.vo.dooradmin.StuLeaveApplyDetailsVo;
import com.xjc.business.service.StudentLeaveApplysService;
import com.xjc.system.constants.MyConstants;
import com.xjc.system.exception.MyException;
import com.xjc.system.result.Result;
import com.xjc.system.result.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 徐锦程
 * 时间:2025-02-06 9:21
 */
@RestController
@RequestMapping("/door/leave_apply")
public class DoorLeaveApplyController {

    @Autowired
    StudentLeaveApplysService studentLeaveApplysService;

    /**
     * 获取请假申请详情
     * @param id 请假记录id
     * @return 请假申请详情
     */
    @GetMapping("/details/{id}")
    public Result<StuLeaveApplyDetailsVo> getLeaveApplyDetails(@PathVariable(value = "id",required = false) Integer id){
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return studentLeaveApplysService.getLeaveApplyDetails(id);
    }

    /**
     * 验证请假申请
     * @param id 请假记录id
     * @return 是否验证成功
     */
    @GetMapping("/validate/{id}")
    public Result<Boolean> validateLeaveApply(@PathVariable(value = "id",required = false) Integer id){
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }
        return studentLeaveApplysService.validateLeaveApply(id);
    }

    /**
     * 销假
     * @param id 请假记录id
     * @return 反馈
     */
    @GetMapping("/change_status/{id}")
    public Result<String> changeStatus(@PathVariable(value = "id",required = false) Integer id){
        if (id == null){
            throw new MyException(ResultCode.SUCCESS.getCode(), MyConstants.PARAM_MISSING);
        }

        return studentLeaveApplysService.changeStatus(id);
    }
}
